package com.example.doctor.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.example.common.Dto;
import com.example.common.DtoUtil;
import com.example.mapper.GdDoctorMapper;
import com.example.mapper.GdInfoDicMapper;
import com.example.mapper.GdUserDoctorAttentionMapper;
import com.example.pojo.GdDoctor;
import com.example.pojo.GdInfoDic;
import com.example.pojo.GdUserDoctorAttention;
import com.example.service.RpcDoctorService;
import com.example.utils.Constants;
import com.example.utils.MqUtils;
import com.example.vo.DeptInfoVo;
import com.example.vo.DoctorDetailsReturnVo;
import com.example.vo.DoctorIntroduceReturnVo;
import com.example.vo.OrderMessageVo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by LENOVO on 2018/9/23.
 */
@Component
@Service(interfaceClass = RpcDoctorService.class)
public class RpcDoctorServiceImpl implements RpcDoctorService {

    @Resource
    private GdDoctorMapper gdDoctorMapper;
    @Resource
    private GdInfoDicMapper gdInfoDicMapper;
    @Resource
    private MqUtils mqUtils;

    @Resource
    private GdUserDoctorAttentionMapper gdUserDoctorAttentionMapper;

    @Override
    public DoctorDetailsReturnVo selectDetailsById(Long id) throws Exception {

        return gdDoctorMapper.selectDetailsById(id);
    }

    @Override
    public DoctorIntroduceReturnVo selectDotorIntroduceById(Long id) throws Exception {

        return gdDoctorMapper.selectDotorIntroduceById(id);
    }

    @Override
    public boolean attentionDoctor(GdUserDoctorAttention gdUserDoctorAttention) throws Exception {

        return  gdUserDoctorAttentionMapper.insertSelective(gdUserDoctorAttention)>0;
    }

    @Override
    public boolean cancelAttentionDoctor(GdUserDoctorAttention gdUserDoctorAttention) throws Exception {
        return  gdUserDoctorAttentionMapper.deleteAttentionDoctor(gdUserDoctorAttention)>0;
    }

    @Override
    public Dto sendOrderMessage(OrderMessageVo orderMessageVo) throws Exception {

        try {
              DoctorDetailsReturnVo doctorDetailsReturnVo= gdDoctorMapper.selectDetailsById(orderMessageVo.getDoctorId());
              orderMessageVo.setDoctorName(doctorDetailsReturnVo.getName());
              orderMessageVo.setProfessionalName(doctorDetailsReturnVo.getProfessionalName());
              mqUtils.sendMessage(Constants.QueueName.TO_CREATE_ORDER, orderMessageVo);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("发送失败", "0002");
        }
        return DtoUtil.returnSuccess();
    }

    @Override
    public List<GdInfoDic> getDeptInfo(Map map) throws Exception {
        return gdInfoDicMapper.selectDeptInfo(map);
    }

    @Override
    public List<GdDoctor> getRecommendDoctorList(Map map) throws Exception {
        return gdDoctorMapper.selectRecommendDoctor(map);
    }


}
